pub mod http;
pub mod ws;

use std::{sync::Arc, time::Instant};

use serde::Deserialize;
use tokio::sync::{broadcast, RwLock};

use crate::{config::Config, monitor::NicMonitor};

#[derive(Debug, Clone, Copy)]
pub enum ServerCommand {
    Stop,
}

#[derive(Clone)]
pub struct AppState {
    pub config: Arc<RwLock<Config>>,
    pub monitor: NicMonitor,
    pub shutdown_tx: broadcast::Sender<ServerCommand>,
    pub start_time: Instant,
}

impl AppState {
    pub fn new(
        config: Arc<RwLock<Config>>,
        monitor: NicMonitor,
        shutdown_tx: broadcast::Sender<ServerCommand>,
        start_time: Instant,
    ) -> Self {
        Self {
            config,
            monitor,
            shutdown_tx,
            start_time,
        }
    }
}

#[derive(Debug, Deserialize, Clone)]
pub struct AuthQuery {
    pub token: Option<String>,
}
